package com.xuelang.pipeline.artifact.domain.resource.service.impl;

import com.xuelang.pipeline.artifact.client.common.result.PageRecord;
import com.xuelang.pipeline.artifact.client.common.util.BizAssert;
import com.xuelang.pipeline.artifact.client.resource.dto.RepositoryPackageQuery;
import com.xuelang.pipeline.artifact.domain.resource.RepositoryPackage;
import com.xuelang.pipeline.artifact.domain.resource.repository.RepositoryPackageRepository;
import com.xuelang.pipeline.artifact.domain.resource.service.RepositoryPackageDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 仓库制品包领域服务实现类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Service
public class RepositoryPackageDomainServiceImpl implements RepositoryPackageDomainService {

    @Autowired
    private RepositoryPackageRepository repositoryPackageRepository;

    @Override
    public PageRecord<RepositoryPackage> pageList(long currentPage, long pageSize, RepositoryPackageQuery repositoryPackageQuery) {
        //BizAssert.isTrue(Nexus3V1Enum.RepositoryFormatEnum.isValid(condition.getFormat()), "组件格式不正确.取值范围为: apt,bower,cocoapods,conan,docker,gitlfs,go,helm,maven2,npm,nuget,p2,pypi,r,raw,rubygems,yum.");
        BizAssert.notNull(repositoryPackageQuery.getArtifactUuid(), "制品仓库uuid不能为空");
        return repositoryPackageRepository.pageList(currentPage, pageSize, repositoryPackageQuery);
    }

    @Override
    public List<RepositoryPackage> list(RepositoryPackageQuery repositoryPackageQuery) {
        //BizAssert.isTrue(Nexus3V1Enum.RepositoryFormatEnum.isValid(condition.getFormat()), "组件格式不正确.取值范围为: apt,bower,cocoapods,conan,docker,gitlfs,go,helm,maven2,npm,nuget,p2,pypi,r,raw,rubygems,yum.");
        BizAssert.notNull(repositoryPackageQuery.getArtifactUuid(), "制品仓库uuid不能为空");
        return repositoryPackageRepository.list(repositoryPackageQuery);
    }

    @Override
    public Boolean save(RepositoryPackage repositoryPackage) {
        return repositoryPackageRepository.save(repositoryPackage);
    }

    @Override
    public Boolean update(RepositoryPackage repositoryPackage) {
        return repositoryPackageRepository.update(repositoryPackage);
    }

    @Override
    public Boolean delete(String repositoryPackageUuid) {
        return repositoryPackageRepository.delete(repositoryPackageUuid);
    }

    @Override
    public RepositoryPackage query(String repositoryPackageUuid) {
        return repositoryPackageRepository.query(repositoryPackageUuid);
    }

    @Override
    public RepositoryPackage queryByPackage(String instanceRepositoryName, String name, String group, String format) {
        return repositoryPackageRepository.queryByPackage(instanceRepositoryName, name, group, format);
    }

    @Override
    public void updateByPackage(String instanceRepositoryName, String name, String group, String format, String version) {
        repositoryPackageRepository.updateByPackage(instanceRepositoryName, name, group, format, version);
    }

    @Override
    public RepositoryPackage queryByPackageName(String instanceRepositoryName, String packageName) {
        return repositoryPackageRepository.queryByPackageName(instanceRepositoryName, packageName);
    }

    @Override
    public void updateByPackageName(String instanceRepositoryName, String packageName, String version, String format) {
        repositoryPackageRepository.updateByPackageName(instanceRepositoryName, packageName, version, format);
    }

}
